package juan.happyge.plugin.myi.view.factory;

import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SearchableConfigurable;
import juan.happyge.plugin.myi.view.page.SettingView;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

/**
 * @Author happyge
 * @Date 14:28 2022/6/24
 * @Description
 * 在idea的settings菜单栏中加入我们的写的settingView界面
 */
public class SettingViewFactory implements SearchableConfigurable {

    public static SettingView settingView;

    @NonNls
    @NotNull
    @Override
    public String getId() {
        return "MoYuIntegration.id";
    }

    @Nls(capitalization = Nls.Capitalization.Title)
    @Override
    public  String getDisplayName() {
        return "MoYuIntegration-config";
    }

    @Nullable
    @Override
    public JComponent createComponent() {
        if (settingView == null) {
            settingView = new SettingView();
        }
        settingView.init();
        return settingView.settingJPanel;
    }

    @Override
    public boolean isModified() {
        return true;
    }

    @Override
    public void apply() throws ConfigurationException {
        settingView.save();
    }

}
